package com.example.task1.ui;

import android.app.Application;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.task1.MainActivity;
import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.listener.OnPageChangeListener;

import java.util.Arrays;
import java.util.List;

public class BootPageActivity extends AppCompatActivity {

    private Banner banner;
    private Button btnHome;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_boot_page);
        getSupportActionBar().hide();
        initView();
        setPage();
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        btnHome.setOnClickListener(v -> {
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();
        });
    }

    private void setPage() {
        List<Integer> page = Arrays.asList(R.mipmap.p1, R.mipmap.p3, R.mipmap.p4, R.mipmap.p5, R.mipmap.p2);
        banner.setAdapter(new BannerImageAdapter<Integer>(page) {
            @Override
            public void onBindView(BannerImageHolder bannerImageHolder, Integer integer, int i, int i1) {
                Glide.with(MyApplication.sContext).load(integer).into(bannerImageHolder.imageView);
            }
        });
        banner.setIndicator(new CircleIndicator(MyApplication.sContext), true);
        banner.addOnPageChangeListener(new OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                if (i == 4) {
                    btnHome.setVisibility(View.VISIBLE);
                } else {
                    btnHome.setVisibility(View.GONE);

                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

    private void initView() {
        banner = findViewById(R.id.banner);
        btnHome = findViewById(R.id.btn_home);
    }
}